﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Text;
using System.Web;

namespace DLULearningNetwork.Libs
{
    public class EmailHelper
    {
        private const string EMAIL_FROM = "cactusdlu@gmail.com";
        private const string PASSWORD = "it.dlu.edu.vn";

        public static bool SendMail(string mailTo, string subject, string body)
        {
            try
            {
                MailMessage msg = new MailMessage();
                msg.From = new MailAddress(EMAIL_FROM);
                msg.To.Add(mailTo);

                msg.Subject = subject;
                msg.Body = body;

                msg.SubjectEncoding = Encoding.UTF8;
                msg.BodyEncoding = Encoding.UTF8;

                SmtpClient client = new SmtpClient();
                client.Credentials = new NetworkCredential(EMAIL_FROM, PASSWORD);
                client.Host = "smtp.gmail.com";
                client.Port = 587;
                client.EnableSsl = true;
                client.Send(msg);
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}